import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
import { SITE_TITLE, SITE_DESCRIPTION } from '../consts';

export async function GET(context) {
	const posts = await getCollection('blog');
	const items = posts.map( post => {
		const [locale, ...slug] = post.slug.split('/');
		return {
			...post.data,
			link: `${locale}/blog/${slug.join('/')}/`,
		};
	});
	return rss({
		title: SITE_TITLE,
		description: SITE_DESCRIPTION,
		site: context.site,
		items,
	});
}
